package org.example;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.charset.StandardCharsets;
import java.util.UUID;

public class Producer {
    private final static String QUEUE_NAME = "queue_name1";
    private static final Logger LOG = LoggerFactory.getLogger(Producer.class);
    public static void main(String[] argv) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        factory.setUsername("duoduo");
        factory.setPassword("123456");
        try (Connection connection = factory.newConnection();
             Channel channel = connection.createChannel()) {
            channel.queueDeclare(QUEUE_NAME, true, false, false, null);
            String uuid = UUID.randomUUID().toString();
            String message = "{" +
                    "\"navigationMode\": 1," +
                    "\"points\": [{\"lon\": 121.00, \"lat\": 7.00}, {\"lon\": 124.00, \"lat\": 8.671383662932286}]," +
                    "\"uuid\":\"" + uuid + "\", " +
                    "\"coarse_path\": " +
                    "[{\"lon\": 121.35191085048595, \"lat\": 18.66431561231426}, " +
                    "{\"lon\": 121.30671673629185, \"lat\": 18.678697160768124}, " +
                    "{\"lon\": 121.193922127344, \"lat\": 18.62824002651597}, " +
                    "{\"lon\": 121.17514779693454, \"lat\": 18.634413239338823}, " +
                    "{\"lon\": 121.10810637554076, \"lat\": 18.652638794471763}, " +
                    "{\"lon\": 121.01402831740643, \"lat\": 18.626123884329893}, " +
                    "{\"lon\": 120.85686168606969, \"lat\": 18.646845605566536}, " +
                    "{\"lon\": 120.81072315243217, \"lat\": 18.654254927525486}, " +
                    "{\"lon\": 120.77055426167718, \"lat\": 18.627194972068807}, " +
                    "{\"lon\": 120.68913491795365, \"lat\": 18.587583536534382}, " +
                    "{\"lon\": 120.60771557423014, \"lat\": 18.54797210099996}, " +
                    "{\"lon\": 120.5630822237347, \"lat\": 18.508840434301614}, " +
                    "{\"lon\": 120.33634197190321, \"lat\": 18.431473420489027}, " +
                    "{\"lon\": 120.34230880535893, \"lat\": 18.378966036840943}, " +
                    "{\"lon\": 120.33952420903589, \"lat\": 18.340999361691054}, " +
                    "{\"lon\": 120.2849459385072, \"lat\": 18.22361848302763}, " +
                    "{\"lon\": 120.26271967785, \"lat\": 17.990816283582667}, " +
                    "{\"lon\": 120.22795643256258, \"lat\": 17.757857143323875}, " +
                    "{\"lon\": 120.32395642394123, \"lat\": 17.557953704516116}, " +
                    "{\"lon\": 120.36133764461127, \"lat\": 17.441895522986897}, "  +
                    "{\"lon\": 120.2753383196744, \"lat\": 17.2491111163098}, "  +
                    "{\"lon\": 120.2750687935569, \"lat\": 17.032358879030703}, "  +
                    "{\"lon\": 120.31146276854444, \"lat\": 16.923457130252533}, "  +
                    "{\"lon\": 120.31024461549156, \"lat\": 16.82287881351573}, "  +
                    "{\"lon\": 120.30220748775554, \"lat\": 16.77844630078236}, "  +
                    "{\"lon\": 120.28946427465016, \"lat\": 16.73357269686565}, "  +
                    "{\"lon\": 120.27672106154476, \"lat\": 16.688699092948944}, "  +
                    "{\"lon\": 120.26613368969967, \"lat\": 16.611908227959837}, "  +
                    "{\"lon\": 120.27763048360082, \"lat\": 16.552384063430424}, "  +
                    "{\"lon\": 120.28912727750196, \"lat\": 16.49285989890101}, "  +
                    "{\"lon\": 120.32683650241731, \"lat\": 16.288874058155898}, "  +
                    "{\"lon\": 120.26721214725859, \"lat\": 16.165784142216992}, "  +
                    "{\"lon\": 120.29891766050167, \"lat\": 16.118272376829893}"  +
                    "]}";
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes(StandardCharsets.UTF_8));
            LOG.info(" [x] Sent '" + message + "'");
        }
    }
}